package com.yc.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.edu.dao.DigitalPeopleDAO;
import com.yc.edu.dao.MessageDAO;
import com.yc.edu.pojo.DigitalPeople;
import com.yc.edu.pojo.Message;
import com.yc.edu.service.DigitalPeopleService;
import com.yc.edu.vo.Text;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DigitalPeopleServiceImpl extends ServiceImpl<DigitalPeopleDAO, DigitalPeople> implements DigitalPeopleService {
    @Autowired
    private DigitalPeopleDAO digitalPeopleDAO;

    @Resource
    private MessageDAO messageDAO;

    @Override
    public List<DigitalPeople> getDigitalPeopleList() {
        List<DigitalPeople> list= digitalPeopleDAO.getDigitalPeopleList();
        return list;
    }

    @Override
    public List<Text> getChatHistory(String name, String dialogUser) {
        List<Text> chatHistory = new ArrayList<>();
        List<Message> messages = messageDAO.getMessagesByUsernames(name, dialogUser);
        for (Message message : messages) {
            chatHistory.add(new Text(message.getUsername().equals(name) ? "user" : "assistant", message.getMessage()));
        }
        return chatHistory;
    }

}
